/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package opds.kurs.work.core;

import java.lang.Math;

/**
 *
 * @author pol
 */
public class TableMethod {

    public static int[][] getTable(int[][] g) {
        int[][] t = new int[32][15];
        for (int i = 0; i < 32; i++) {
            if (i % 2 >= 1) {
                t[i][4] = 1;
            }
            if (i % 4 >= 2) {
                t[i][3] = 1;
            }
            if (i % 8 >= 4) {
                t[i][2] = 1;
            }
            if (i % 16 >= 8) {
                t[i][1] = 1;
            }
            if (i % 32 >= 16) {
                t[i][0] = 1;
            }
            for (int j = 0; j < 5; j++) {
                if (t[i][j] == 1) {
                    sumVector(t[i], g[j]);
                }
            }
        }
        for (int i = 0; i < 32; i++) {
            for (int j = 0; j < 15; j++) {
                System.out.print(t[i][j] + " ");
            }
            System.out.println();
        }
        return t;
    }

    public static void sumVector(int[] first, int[] second) {
        for (int i = 5; i < 15; i++) {
            if ((Math.max(first[i], second[i]) == 1) && (first[i] != second[i])) {
                first[i] = 1;
            } else {
                first[i] = 0;
            }
        }
    }

    public static int[] mulVecOnMatrix(int[] vec, int[][] matrix) {
        int[] res = new int[matrix[0].length];
        for (int i = 0; i < vec.length; i++) {
            for (int j = 0; i < matrix[0].length; i++) {
                res[j] += vec[i] * matrix[i][j];
            }
        }
        System.out.println("result is :");
        for (int i = 0; i < res.length; i++) {
            System.out.print(res[i] + " ");
        }
        return res;
    }

    public static int[][] getTransporate(int[][] matrix) {
        int[][] res = new int[matrix[0].length][matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                res[j][i] = matrix[i][j];
            }
        }
        for (int i = 0; i < res.length; i++) {
            for (int j = 0; j < res[0].length; j++) {
                System.out.print(res[i][j] + " ");
            }
            System.out.println();
        }
        return res;
    }

    public static int[] getF(String str, int[][] table) {
        int[] res;
        res = table[Integer.parseInt(str, 2)];
        return res;
    }

    public static int[] decode(int[] h, int[][] table,int[][] res) {
        int[] ves = new int[table.length];
        for (int i = 0; i < table.length; i++) {
            for (int j = 0; j < table[0].length; j++) {
                res[i][j] = h[j] ^ table[i][j];
                if (res[i][j] == 1) {
                    ves[i]++;
                }
                System.out.print(table[i][j]+" ");
            }
            System.out.println(ves[i]);
        }
        return ves;
    }
    
    public static boolean cmpVec(int[] vec1,int[] vec2){
        boolean f=true;
        for(int i=0;i<vec1.length;i++){
            if (vec1[i]!=vec2[i]) {
                f=false;
            }
        }
        return f;
    }
    
    public static int getMinVes(int[] ves, int[] row){
        int min=ves[0];
        for(int i=1;i<ves.length;i++){
            if (ves[i]<=min) {
                min=ves[i];
                row[0]=i;
            }
        }
        return min;
    }
    
    public static int[] getH(String str, int[] f) {
        int[] res = new int[str.length()];
        if (f != null) {
            for (int i = 0; i < str.length(); i++) {
                res[i] = ((int) (str.toCharArray()[i] - 48)) ^ f[i];
                System.out.print(res[i] + " ");
            }
        }
        return res;
    }
}
